package com.ruoyi.web.controller.member.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.member.MemberCouponDO;
import com.ruoyi.common.entity.DO.member.MemberVipTypeDO;
import com.ruoyi.common.entity.VO.CouponSearchVO;
import com.ruoyi.common.entity.VO.CouponVO;
import com.ruoyi.common.entity.VO.member.MemberCouponVO;
import com.ruoyi.common.entity.VO.member.MemberVipTypeSearchVO;
import com.ruoyi.common.entity.VO.member.MemberVipTypeVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface IBackMemberCouponMapper extends BaseMapper<MemberCouponDO> {

    List<MemberCouponVO> searchMemberCouponList(CouponSearchVO searchVO);


    @Select("SELECT COUNT(1) FROM member_coupon where member_id=#{memberId} and coupon_id=#{couponId}")
    int memberGetCoupon(@Param("memberId") Long memberId, @Param("couponId") Long couponId);

    @Update("UPDATE member_coupon set member_coupon_status=0 where id=#{couponId} and member_coupon_status=1")
    int cancelRollBack(@Param("memberId") Long memberId, @Param("couponId") Long couponId);

    @Select("SELECT openid,title,coupon_type couponType,face_value faceValue,discount,use_end_time useEndTime FROM member_coupon mc " +
            "left join coupon c on mc.coupon_id=c.id " +
            "left join member m on mc.member_id=m.id " +
            "where c.shop_id=#{shopId} and member_coupon_status=0 and DATE_FORMAT(curdate(), '%Y-%m-%d') = SUBDATE(c.use_end_time,INTERVAL #{expireRemindAt} DAY)")
    List<MemberCouponVO> searchExpireRemindList(@Param("shopId") Long shopId, @Param("expireRemindAt") String expireRemindAt);
}
